#include <stdio.h>
#include "process.h"
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
    

#define STYLE '='
#define SPACE ' '
#define POINT '.'
#define NUM 101
const int pnum =6;

void Process(double total, double current)
{
    //1.更新当前进度百分比
    double rate = (current / total)*100;

    //2.更新进度条主体
    char bar[NUM];//每1%更新一个字符
    memset(bar,'\0',sizeof(bar));

    for(int i =0 ; i< (int)rate;i++)
    {
        bar[i] = STYLE;
    }

    //3.更新进度条光标
    static int num = 0;
    num++;
    num %= pnum;

    char points[pnum+1];
    memset(points,'\0',sizeof(points));
    for(int i =0 ;i < pnum;i++)
    {
        if(i < num) points[i] = POINT;
        else points[i]= SPACE;
    }

    //4.打印
    printf("[%-100s][%.1lf%%]%s\r",bar,rate,points);
    fflush(stdout);

}
